// 1576. 替换所有的问号
/**
 * @param {string} s
 * @return {string}
 */
var modifyString = function (s) {
    const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    const temp = Array(s.length).fill(0)
    const helper = (prev, next) => {
        return arr.find(cur => {
            if (cur && next) {
                return cur !== prev && cur !== next
            } else {
                return cur !== prev
            }
        })
    }
    for (let i = 0; i < s.length; i++) {
        const curr = s.charAt(i)
        if (curr !== "?") {
            temp[i] = curr
        } else {
            if (!i) {
                const next = s.charAt(i + 1)
                if (next !== "?") {
                    temp[i] = helper(next)
                } else {
                    temp[i] = "a"
                }
            } else {
                const prev = temp[i - 1]
                const next = s.charAt(i + 1)
                temp[i] = helper(prev, next)
            }
        }
    }
    return temp.join("")
};
var modifyString = function (s) {
    const n = s.length
    const arr = [...s]
    for (let i = 0; i < n; i++) {
        if (arr[i] === "?") {
            for (let j = 0; j < 3; j++) {
                // i < n - 1 防止最后一个是'?'
                if (i && arr[i - 1] === String.fromCharCode('a'.charCodeAt() + j) || (i < n - 1 && arr[i + 1]) === String.fromCharCode("a".charCodeAt() + j)) continue
                arr[i] = String.fromCharCode('a'.charCodeAt() + j)
                break
            }
        }
    }
    return arr.join("")
}
modifyString("?a?ub???w?b")